<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div[name=liuyan] p {
            padding-left: 30px;
        }
    </style>
    <script src="../jquery-1.12.4.js"></script>
    <script>
        $(function () {
            const $userName = $("input[name = 'userName']");
            const $userLiuyan = $("textarea[name = 'userLiuyan']");
            const $isNimiing = $("input[name='userNiming'][type = 'checkbox']");
            const $btn = $("input[type = 'button']");
            const $liuyanBan = $("div[name = 'liuyan']");
            const time = new Date();
            let isNi = "";
            $btn.click(() => {
                isNi = "";
                if ($userName.val() === "" || $userLiuyan.val() === "") {
                    alert("昵称和留言不可为空!");
                } else {
                    if ($isNimiing.prop("checked")) {
                        isNi = "匿名";
                    } else {
                        isNi = $userName.val();
                    }
                    let sp_UserName = $(`<span>${isNi}-${time.toLocaleString()}</span>`);
                    let lyb = $userLiuyan.text();
                    let p_Liuyan = $(`<p>${$userLiuyan.val()}</p>`);
                    console.log(sp_UserName);
                    $liuyanBan.prepend(p_Liuyan);
                    $liuyanBan.prepend(sp_UserName);
                }
            });
        })
    </script>
</head>

<body>
    <form action="" method="get">
        <table>
            <tr>
                <td>昵称:</td>
                <td><input type="text" name="userName"></td>
                <td></td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <textarea name="userLiuyan" id="" cols="30" rows="10"></textarea>
                </td>
                <td></td>
            </tr>
            <tr>
                <td></td>
                <td></td>
                <td>
                    <input type="checkbox" name="userNiming">匿名
                    <br>
                    <input type="button" type="button" value="发表">
                </td>
            </tr>
        </table>
        <div name="liuyan">

        </div>
    </form>

</body>

</html>